package com.moji.controller.api;


import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import cn.hutool.captcha.generator.RandomGenerator;
import com.moji.common.base.ApiResult;
import com.moji.common.entity.MyPage;
import com.moji.entity.SysUser;
import com.moji.entity.dto.ModifyPasswordDto;
import com.moji.entity.dto.RespLoginDto;
import com.moji.entity.dto.SysUserDto;
import com.moji.entity.vo.SelectUserVo;
import com.moji.entity.vo.SysUserVo;
import com.moji.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * <p>
 * 人员信息表 前端控制器
 * </p>
 *
 * @author ccl
 * @since 2024-07-20
 */
@RestController
@RequestMapping("api/sysUser")
@Api(tags = "后台用户相关api接口", value = "后台用户相关api接口")
public class SysUserController {

    @Resource
    private SysUserService sysUserService;

    @PostMapping("add")
    @ApiOperation("保存用户")
    public ApiResult add(@RequestBody SysUserDto sysUser){
        return sysUserService.add(sysUser);

    }

    @PostMapping("update")
    @ApiOperation("编辑用户")
    public ApiResult update(@RequestBody SysUserDto sysUser){
        return sysUserService.edit(sysUser);
    }

    @GetMapping("delete")
    @ApiOperation("删除用户")
    public ApiResult delete(Long id){
        return ApiResult.failed(sysUserService.delete(id));
    }

    @PostMapping("queryPage")
    @ApiOperation("分页查询用户")
    public ApiResult<MyPage<SysUserVo>> queryPage(@RequestBody SysUser sysUser){
        MyPage<SysUserVo> ccpSystemUserMyPage = sysUserService.queryPage(sysUser);
        return ApiResult.ok(ccpSystemUserMyPage);
    }

    @GetMapping("detail")
    @ApiOperation(value = "用户详情",response = SysUserVo.class)
    public ApiResult detail(Long id){
        return ApiResult.ok(sysUserService.detail(id));
    }

    @GetMapping("resetPassword")
    @ApiOperation("用户重置密码")
    public ApiResult resetPassword(Long id){
        return ApiResult.ok(sysUserService.resetPassword(id));
    }

    @PostMapping("modifyPassword")
    @ApiOperation("用户修改密码")
    public ApiResult modifyPassword(@RequestBody ModifyPasswordDto modifyPasswordDao){
            return ApiResult.ok(sysUserService.modifyPassword(modifyPasswordDao));
    }

    @PostMapping("userSelect")
    @ApiOperation(value = "查询用户下拉框",response = SelectUserVo.class)
    public ApiResult<List<SelectUserVo>> findUserList() {
            return ApiResult.ok(sysUserService.userSelect());
    }

    @GetMapping("queryUserInfo")
    @ApiOperation(value = "查询用户信息(含权限)",response = RespLoginDto.class)
    public ApiResult<RespLoginDto> queryUserInfo() {
        return ApiResult.ok(sysUserService.queryUserInfo());
    }



}

